<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <parent>
    <groupId>org.camunda.bpm.qa.upgrade</groupId>
    <artifactId>camunda-qa-db-instance-migration</artifactId>
    <version>7.20.0-SNAPSHOT</version>
  </parent>

  <artifactId>camunda-qa-upgrade-test-fixture-710</artifactId>
  <packaging>jar</packaging>
  <name>Camunda Platform - QA - upgrade - instance migration - test fixture - 7.10.0</name>

  <properties>
    <camunda.version.previous>7.9.0</camunda.version.previous>
    
    <version.h2>${version.h2-v1}</version.h2>
  </properties>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.camunda.bpm</groupId>
        <artifactId>camunda-bom</artifactId>
        <version>7.10.0</version>
        <scope>import</scope>
        <type>pom</type>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.spin</groupId>
      <artifactId>camunda-spin-dataformat-json-jackson</artifactId>
    </dependency>
    <dependency>
      <groupId>org.camunda.bpm</groupId>
      <artifactId>camunda-engine-plugin-spin</artifactId>
    </dependency>

    <dependency>
      <groupId>org.camunda.bpm.qa.upgrade</groupId>
      <artifactId>camunda-qa-upgrade-scenario-util</artifactId>
      <version>${project.version}</version>
    </dependency>

    <dependency>
      <groupId>org.codehaus.groovy</groupId>
      <artifactId>groovy-jsr223</artifactId>
    </dependency>
  </dependencies>

  <build>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
        <filtering>true</filtering>
      </resource>
    </resources>
    <testResources>
      <testResource>
        <directory>src/test/resources</directory>
        <filtering>true</filtering>
      </testResource>
    </testResources>
  </build>

  <profiles>
    <profile>
      <id>instance-migration</id>
      <build>
        <plugins>
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-antrun-plugin</artifactId>
            <executions>
              <execution>
                <id>create-sql-script-stubs</id>
                <phase>generate-test-sources</phase>
                <configuration>
                  <target>
                    <property name="current.minor.version" value="${camunda.current.majorVersion}.${camunda.current.minorVersion}" />
                    <property name="previous.minor.version" value="${camunda.previous.majorVersion}.${camunda.previous.minorVersion}" />
                    <property name="current.sql.upgrade.dir" value="${project.build.directory}/scripts-current/sql/upgrade" />
                    <property name="minor.version.upgrade.script.previous.to.current.engine" value="${database.type}_engine_${previous.minor.version}_to_${current.minor.version}.sql" />
                    <property name="minor.version.upgrade.script.previous.to.current.identity" value="${database.type}_identity_${previous.minor.version}_to_${current.minor.version}.sql" />
                    <property name="patch.version.upgrade.script.previous.engine.prefix" value="${database.type}_engine_${previous.minor.version}_patch_${previous.minor.version}" />

                    <!-- create the SQL scripts so that the files exist even if they do not exist in the distribution. (this can be the case if there are no db
                      upgrades (yet) for a particular release ) -->

                    <mkdir dir="${current.sql.upgrade.dir}/" />

                    <!-- concanated patches for last minor version -->
                    <!-- 7.9.0 is on a clean state so we can again use the concanated patches -->
                    <touch file="${project.build.directory}/scripts-current/sql/upgrade/${database.type}_engine_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}_patch.sql" />
                    <touch file="${project.build.directory}/scripts-current/sql/upgrade/${database.type}_identity_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}_patch.sql" />

                    <!-- minor version upgrade from previous to current version -->
                    <touch file="${current.sql.upgrade.dir}/${minor.version.upgrade.script.previous.to.current.engine}" />
                    <touch file="${current.sql.upgrade.dir}/${minor.version.upgrade.script.previous.to.current.identity}" />
                  </target>
                </configuration>
                <goals>
                  <goal>run</goal>
                </goals>
              </execution>
            </executions>
          </plugin>

          <!-- provide sql scripts -->
          <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <executions>
              <execution>
                <id>unpack-current-sql-scripts</id>
                <phase>generate-test-sources</phase>
                <goals>
                  <goal>unpack</goal>
                </goals>
                <configuration>
                  <artifactItems>
                    <artifactItem>
                      <groupId>org.camunda.bpm.distro</groupId>
                      <artifactId>camunda-sql-scripts</artifactId>
                      <version>7.10.0</version>
                      <type>test-jar</type>
                      <outputDirectory>${project.build.directory}/scripts-current</outputDirectory>
                      <overWrite>true</overWrite>
                    </artifactItem>
                  </artifactItems>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <!-- parse version properties from qa/pom.xml -->
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>build-helper-maven-plugin</artifactId>
            <executions>
              <execution>
                <id>parse-current-version</id>
                <goals>
                  <goal>parse-version</goal>
                </goals>
                <configuration>
                  <propertyPrefix>camunda.current</propertyPrefix>
                  <versionString>7.10.0</versionString>
                </configuration>
              </execution>
              <execution>
                <id>parse-old-version</id>
                <goals>
                  <goal>parse-version</goal>
                </goals>
                <configuration>
                  <propertyPrefix>camunda.previous</propertyPrefix>
                  <versionString>${camunda.version.previous}</versionString>
                </configuration>
              </execution>
            </executions>
          </plugin>

          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>sql-maven-plugin</artifactId>
            <configuration>
              <skip>${skip-test-fixture}</skip>
            </configuration>
            <executions>
              <execution>
                <id>patch-previous-schema</id>
                <phase>test-compile</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <srcFiles>
                    <!-- now patch old version of the schema -->
                    <!--<srcFile>${project.build.directory}/scripts-current/sql/upgrade/${database.type}_engine_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}_patch_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}.x_to_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}.y.sql</srcFile>-->
                    <srcFile>${project.build.directory}/scripts-current/sql/upgrade/${database.type}_engine_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}_patch.sql</srcFile>
                    <srcFile>${project.build.directory}/scripts-current/sql/upgrade/${database.type}_identity_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}_patch.sql</srcFile>
                  </srcFiles>
                </configuration>
              </execution>
              <execution>
                <id>upgrade-db</id>
                <phase>test-compile</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <srcFiles>
                    <!-- now perform the schema migrations -->
                    <srcFile>${project.build.directory}/scripts-current/sql/upgrade/${database.type}_engine_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}_to_${camunda.current.majorVersion}.${camunda.current.minorVersion}.sql</srcFile>
                    <srcFile>${project.build.directory}/scripts-current/sql/upgrade/${database.type}_identity_${camunda.previous.majorVersion}.${camunda.previous.minorVersion}_to_${camunda.current.majorVersion}.${camunda.current.minorVersion}.sql</srcFile>
                  </srcFiles>
                </configuration>
              </execution>
              <!-- example: patch-current-schema
              <execution>
                <id>patch-current-schema</id>
                <phase>test-compile</phase>
                <goals>
                  <goal>execute</goal>
                </goals>
                <configuration>
                  <srcFiles>
                    // now patch current version of the schema
                    // example for aggregate patching of current version
                    <srcFile>${project.build.directory}/scripts-current/sql/upgrade/${database.type}_engine_${camunda.current.majorVersion}.${camunda.current.minorVersion}_patch.sql</srcFile>
                    <srcFile>${project.build.directory}/scripts-current/sql/upgrade/${database.type}_identity_${camunda.current.majorVersion}.${camunda.current.minorVersion}_patch.sql</srcFile>
                  </srcFiles>
                </configuration>
              </execution>
              -->
            </executions>
          </plugin>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <configuration>
              <cleanupDaemonThreads>false</cleanupDaemonThreads>
              <includeProjectDependencies>true</includeProjectDependencies>
              <includePluginDependencies>false</includePluginDependencies>
              <classpathScope>test</classpathScope>
              <skip>${skip-test-fixture}</skip>
            </configuration>
            <executions>
              <execution>
                <id>create-test-fixture</id>
                <goals>
                  <goal>java</goal>
                </goals>
                <phase>process-test-classes</phase>
                <configuration>
                  <mainClass>org.camunda.bpm.qa.upgrade.TestFixture</mainClass>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </profile>
    <profile>
      <id>cockroachdb</id>
      <properties>
        <skip-test-fixture>true</skip-test-fixture>
      </properties>
    </profile>
  </profiles>

</project>
